package com.malphite.mongodemo.service;

import com.malphite.mongodemo.bean.Population;
import com.malphite.mongodemo.dao.DemoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.*;
import org.springframework.data.mongodb.core.geo.GeoJsonModule;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DemoServiceImpl implements DemoService{
    @Autowired
    DemoDao demoDao;

    @Autowired
    MongoTemplate mongoTemplate;

    public void test001(){

        demoDao.save(new Population());
    }

    public void test003(){

        //mongoTemplate.getCollection("").
        //mongoTemplate
    }


    public void test002(){

        Criteria.where("").near(new Point(1d,2d)).maxDistance(1d);
        Criteria criteria = new Criteria();
        criteria.and("").lt(100);

        GeoJsonModule module = new GeoJsonModule();
        ProjectionOperation project = Aggregation.project("","");
        //MatchOperation match = Aggregation.match();
        LimitOperation limit = Aggregation.limit(100);
        SortOperation sort = Aggregation.sort(Sort.Direction.ASC, "");
        GroupOperation group = Aggregation.group("");
        TypedAggregation<Population> populationTypedAggregation = Aggregation.newAggregation(Population.class, project, limit, sort, group);
        AggregationResults<Population> aggregate = mongoTemplate.aggregate(populationTypedAggregation, Population.class);
        List<Population> mappedResults = aggregate.getMappedResults();
    }
}
